<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     pagizer
 * @subpackage  medias
 */

class m_medias_actions_AjaxEditImageAction extends m_backoffice_extends_Action
{
	public function execute()
	{
		$docId = $this->getRequestParameter("docId");
		$folderId = $this->getRequestParameter("folderId");
		$docLang = $this->getRequestParameter("docLang");
		$width = $this->getRequestParameter("width");
		$height = $this->getRequestParameter("height");
		
		$media = f_document_Provider::getInstance()->getByModelAndUniqueId('medias/Media', $docId, $docLang);
		
		$parameters = m_medias_services_ParameterService::getInstance()->getParametersByFolderId($folderId, $docLang);
		
		$image = $media->getFileUrl($media->getFileNameWoExt().".".$media->getExtension());

		$user = $this->getUserContext()->getUser();
        $this->setDisplayLang($user->getBackLang());

        $this->addToModel("size", array($width,$height));
		$this->addToModel("parameters", $parameters);
		$this->addToModel("media", $media);
		$this->addToModel("image", $image);
		$this->setView('success');
	}	
	
	public function validate()
	{
		return $this->getUserContext()->hasRight(array("backoffice_accessBo", "medias_Edit"));
	}

    public function errorHandler()
    {
        return "";
    }
}